//
//  TrailView.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/11.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "TrailView.h"
#import "CommonMacro.h"
#import "HaveApplyView.h"
#import "ReportVIew.h"

@interface TrailView ()<HaveApplyViewDelegate,reportTrailSideBarDelegate>
{
    HaveApplyView *haveApplay;
    ReportVIew *reportView;
    
}


@end


@implementation TrailView


- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
         [self initContent];
         [self initSubViews];
    }
    return self;
}

-(void)initSubViews
{
    haveApplay = [[HaveApplyView alloc] initWithFrame:CGRectMake(10, SCREEN_HEIGHT*13/128, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.68)];
    haveApplay.backgroundColor = [UIColor blueColor];
    haveApplay.delegate = self;
    [self addSubview:haveApplay];
    
    reportView = [[ReportVIew alloc] initWithFrame:CGRectMake(0, 80, SCREEN_WIDTH, SCREEN_HEIGHT*0.68 )];
    reportView.reportTrailDelegate = self;
    [self addSubview:reportView];
    reportView.hidden = YES;
}

- (void)initContent
{
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:@[@"已申请",@"试用报告"]];
    segment.frame = CGRectMake(-5, 0, 330, 40);
    segment.selectedSegmentIndex = 0;//设置索引默认选择项
    segment.tintColor = UIColorWithRGBA(203, 203, 203, 1);
    [self addSubview:segment];
    self.segment = segment;
    [self.segment addTarget:self  action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged];
}

//具体委托方法实例
-(void)segmentAction:(UISegmentedControl *)Seg{
    NSInteger  index = Seg.selectedSegmentIndex;

    switch (index) {
        case 0:
            haveApplay.hidden = NO;
            reportView.hidden = YES;

            break;
        case 1:
            haveApplay.hidden = YES;
            reportView.hidden = NO;

            break;
        default:
            break;
    }
}

#pragma mark - HaveApplyViewDelegate

- (void)applySideBar:(HaveApplyView *)sideBar didSelectAtIndex:(NSInteger)index
{
    NSLog(@"点击了  已申请");
    if ([self.applayDelegate respondsToSelector:@selector(applyHaveSideBar:didSelectAtIndex:)]) {
        [self.applayDelegate applyHaveSideBar:self didSelectAtIndex:index];
    }
}

#pragma mark- reportTrailSideBarDelegate
- (void)reportTrailSideBarRe:(ReportVIew *)sideBar didSelectAtIndex:(NSInteger)index
{
    NSLog(@"试用报告 地啊你");
    if ([self.reportTraDelegate respondsToSelector:@selector(reportTraSideBarRe:didSelectAtIndex:)]) {
        [self.reportTraDelegate reportTraSideBarRe:self didSelectAtIndex:index];
    }
}
//- (void)sideBarRe:(ReportVIew *)sideBar didSelectAtIndex:(NSInteger)index
//{
//    if ([self.delegate respondsToSelector:@selector(sideBar:didSelectAtIndex:)])
//        [self.delegate sideBar:self didSelectAtIndex:index];
//}
@end
